<?php

namespace app\admin\controller;
use think\facade\View;
use app\admin\logic\GoodsLogic;
use app\admin\model\Goods;

class DesignLogin extends Base{

    public function index(){

        $info = Db::name('design_login')->where('1=1')->find();
        if(!$info){

            $logo    = PRE_URL.'/static/imgsrc/logo.jpg';
            $sysname = '';
            $bgcolor = '';

            $logo = tpCache('shop_info.store_logo');
                $sysname = tpCache('shop_info.store_name');
                $bgcolor = !empty($sysset['color1'])?$sysset['color1']:'';



            $info = array(
                'type'=>1,
                'updatetime'=>time(),
                'data'=>json_encode([
                    "logo"      => $logo,
                    "bgtype"    => 1,
                    "bgcolor"   => $bgcolor,
                    "bgimg"     => getCurUrl().'/static/admin/images/login/bg1.png',
                    "cardcolor" => '#FFFFFF',
                    "titletype" => 'center',
                    "title"     => '欢迎使用'.$sysname,
                    "titlecolor"=> '#000000',
                    "subhead"   => '推荐使用手机号验证码登录',
                    "subheadcolor" => '#A8B5D3',
                    "btntype"   => 1,
                    "btncolor"   => '#0256FF',
                    "btnwordcolor" => '#FFFFFF',
                    "codecolor" => '#0256FF',
                    "regtipcolor"  => '#5E6066',
                    "regpwdbtncolor"  => '#666666',
                    "xytipword"    => '我已阅读并同意',
                    "xytipcolor"   => '#D8D8D8',
                    "xycolor"  => '#0256FF'
                ])
            );
            $id = Db::name('design_login')->insertGetId($info);
            $info['id'] = $id;
        }

        $data = json_decode($info['data'],true);
        View::assign('data',$data);
        View::assign('info',$info);
        View::assign('type',$info['type']);

//        $xyname = "《无》";
//        $xieyi = Db::name('admin_set_xieyi')->where('aid',aid)->field('id,name')->find();
//        if($xieyi){
//            $xyname = !empty($xieyi['name'])?$xieyi['name']:'';
//        }
//        View::assign('xyname',$xyname);
        return View::fetch();
    }
    public function save(){

        $info = input('post.info/a');
        $id = $info['id']?$info['id']:0;
        $info['data'] = json_encode($info['data']);
        $info['updatetime'] = time();

        unset($info['id']);
        if($id){
            Db::name('design_login')->where('id',$id)->update($info);
        }else{
            Db::name('design_login')->insert($info);
        }


        return json(['status'=>1,'msg'=>'保存成功','url'=>(string)url('index')]);
    }
}